package com.yunfangdata.web.controller;


import com.yunfangdata.domain.Curriculumtable;
import com.yunfangdata.query.CurriculumtableQueryObject;
import com.yunfangdata.service.ICurriculumtableService;
import com.yunfangdata.util.JsonResult;
import com.yunfangdata.util.PageResult;
import com.yunfangdata.util.PermissionName;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("curriculumtable")
public class CurriculumtableController {
    @Autowired
    private ICurriculumtableService curriculumtableService;

    @RequestMapping("")
    @PermissionName("课程列表")
    public String index(){
        return "curriculumtable/list";
    }

    @RequestMapping("list")
    @ResponseBody
    public PageResult list(CurriculumtableQueryObject qo){
        System.out.println(curriculumtableService.query(qo));
        return curriculumtableService.query(qo);

    }

    public PageResult query(CurriculumtableQueryObject qo) {
        return this.curriculumtableService.query(qo);
    }


//    @RequiresPermissions("saveOrUpdate")
//    @PermissionName("其他情况更新或保存")
//    @RequestMapping("curriculumtable:saveOrUpdate")
//    @ResponseBody
//    public JsonResult saveOrUpdate(Curriculumtable entity) {
//        JsonResult jsonResult = new JsonResult();
//        if (entity.getId() == null) {
//            try {
//                curriculumtableService.update(entity);
//            } catch (Exception e) {
//                e.printStackTrace();
//                jsonResult = new JsonResult("更新失败");
//            }
//        } else {
//            try {
//                curriculumtableService.save(entity);
//            } catch (Exception e) {
//                e.printStackTrace();
//                jsonResult = new JsonResult("保存失败");
//            }
//        }
//        return jsonResult;
//    }
@RequestMapping("save")
@ResponseBody
@RequiresPermissions("curriculumtable:save")
@PermissionName("课程保存")
public JsonResult save(Curriculumtable entity){
    JsonResult result = new JsonResult();
    try {
        curriculumtableService.save(entity);
    }catch (Exception e){
        e.printStackTrace();
        result = new JsonResult("保存操作失败");
    }
    return result;
}

    @RequestMapping("update")
    @ResponseBody
    @RequiresPermissions("curriculumtable:update")
    @PermissionName("更新教室")
    public JsonResult update(Curriculumtable entity){
        System.out.println("================" +
                entity.toString());
        JsonResult result = new JsonResult();
        try {
            curriculumtableService.update(entity);
        }catch (Exception e){
            e.printStackTrace();
            result = new JsonResult("更新操作失败");
        }
        return result;
    }

    @RequiresPermissions("curriculumtable:delete")
    @PermissionName("删除")
    @RequestMapping("delete")
    @ResponseBody
    public JsonResult delete(Long id) {
        JsonResult jsonResult = new JsonResult();
        if (id != null) {
            try {
                curriculumtableService.delete(id);
            } catch (Exception e) {
                e.printStackTrace();
                jsonResult = new JsonResult("删除失败");
            }
        }
        return jsonResult;
    }



}
